'use strict';
let Response = require('../../../model/Response');
let RestifyProxy = require('../../../util/RestifyProxy');
let CustomPageBean = require('../../../model/CustomPageBean');
let orderService = require('../../../service/workorder/orderService');
let logger = require('../../../util/LoggerUtil').logger('orderController.js');

/**
 * 工单管理——页面
 */
module.exports.orderPage = function () {
    let response = new Response();
    response.render('back/workorder/order/order');
    this.resolve(response);
};
/**
 * 工单管理——数据
 */
module.exports.orderList  = async function () {
    let req = this.req;
    let params = req.body;
    let response = new Response();
    try {
        let result = await orderService.orderList(this, params);
        let pageBean = new CustomPageBean(result);
        response.send(pageBean);
    } catch (error) {
        logger.error(error);
    }
    this.resolve(response);
};
/**
 * 工单管理——详情页面
 */
module.exports.detailPage = function () {
    let response = new Response();
    response.render('back/workorder/order/order_detail');
    this.resolve(response);
};
/**
 * 工单管理——详情数据
 */
module.exports.detailData  = async function () {
    let req = this.req;
    let params = req.body;
    let response = new Response();
    try {
        let result = await orderService.detailData(this, params.userId);
        response.send(result);
    } catch (error) {
        logger.error(error);
    }
    this.resolve(response);
};
/**
 * 工单管理——详情页面——签收按钮
 */
module.exports.signBtn = async function () {
    let req = this.req;
    let params = req.body;
    let response = new Response();
    try {
        let result = await orderService.signBtn(this, params);
        response.send(result);
    } catch (error) {
        logger.error(error);
    }
    this.resolve(response);
};

/**
 * 工单管理——详情页面——废弃按钮
 */
module.exports.discardBtn = async function () {
    let req = this.req;
    let params = req.body;
    let response = new Response();
    try {
        let result = await orderService.discardBtn(this, params);
        response.send(result);
    } catch (error) {
        logger.error(error);
    }
    this.resolve(response);
};
/**
 * 工单管理——详情页面——改派按钮
 */
module.exports.changeBtn = async function () {
    let req = this.req;
    let params = req.body;
    let response = new Response();
    try {
        let result = await orderService.changeBtn(this, params);
        response.send(result);
    } catch (error) {
        logger.error(error);
    }
    this.resolve(response);
};
/**
 * 工单管理——详情页面——审核按钮
 */
module.exports.auditBtn = async function () {
    let req = this.req;
    let params = req.body;
    let response = new Response();
    try {
        let result = await orderService.auditBtn(this, params);
        response.send(result);
    } catch (error) {
        logger.error(error);
    }
    this.resolve(response);
};
/**
 * 工单管理——详情页面——处理按钮
 */
module.exports.disposeBtn = async function () {
    let req = this.req;
    let params = req.body;
    let response = new Response();
    try {
        let result = await orderService.disposeBtn(this, params);
        response.send(result);
    } catch (error) {
        logger.error(error);
    }
    this.resolve(response);
};